package temp;

import com.mysql.cj.jdbc.MysqlDataSource;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class SuperAdminHasAllAuthorities {
    public static void main(String[] args) throws SQLException {
        MysqlDataSource source = new MysqlDataSource();
        source.setURL("jdbc:mysql://127.0.0.1:3306/workerorder_system?useUnicode=true&characterEncoding=UTF8&useSSL=false");
        source.setUser("root");
        source.setPassword("123456");
        Connection connection = source.getConnection();
        Statement statement = connection.createStatement();

        ResultSet resultSet = statement.executeQuery("select id from authority");

        StringBuilder builder = new StringBuilder("deleteLauncher from role_authority;").append("\n");

        int id = 0;

        while (resultSet.next()) {
            id++;

            builder.append("insert into role_authority(id,role_id,authority_id) values('").append(id).append("','0','").append(resultSet.getString("id")).append("')").append(";\n");
        }

        System.out.println(builder.toString());

    }
}
